#include "recognitionview.h"
#include "saveimagedialog.h"
#include "logger.h"

using namespace views;
using namespace utilities;

RecognitionView::RecognitionView()
{
    _viewName = "";
    initUI();
    setupUI();
}

RecognitionView::RecognitionView(const QString& name)
{
    _viewName = name;
    initUI();
    setupUI();
}

RecognitionView::~RecognitionView()
{
    delete(_mainGBox);
    delete(_imageRawArea);
    delete(_imageProcessArea);
    delete(_imageRawWidget);
    delete(_imageProcessWidget);
}

void RecognitionView::initUI()
{
    Logger::logMessage("RecognitionView::initUI()");

    // Initialize UI objects
    _mainGBox           = new QFrame();
    _imageRawWidget     = new ImageWidget(NULL);
    _imageProcessWidget = new ImageWidget(NULL);
}

void RecognitionView::setupUI()
{
    Logger::logMessage("RecognitionView::setupUI()");

    // Setup the main Grid Box
    //_mainGBox->setStyleSheet(QString::fromUtf8("background-color: rgb(0, 255, 255);"));
    this->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 255, 255);"));
    _imageRawWidget->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 255, 255);"));
    _imageProcessWidget->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 255, 255);"));

    QHBoxLayout *imageGLayout = new QHBoxLayout;
    imageGLayout->addWidget(_imageRawWidget);
    imageGLayout->addWidget(_imageProcessWidget);
    //_mainGBox->setLayout(imageGLayout);
    this->setLayout(imageGLayout);

    //this->addWidget(_mainGBox);
}

void RecognitionView::setFrame(QImage& image)
{
    Logger::logMessage("RecognitionView::setFrame(QImage& image)");

    _imageRawWidget->setImage(image);
}

void RecognitionView::setFrame2(QImage& image)
{
    Logger::logMessage("RecognitionView::setFrame2(QImage& image)");

    _imageProcessWidget->setImage(image);
}

QSize RecognitionView::getFrameSize() const
{
    Logger::logMessage("RecognitionView::getFrameSize() const: ");

    return _imageRawWidget->size();
}

void RecognitionView::setViewName(const QString& name)
{
    Logger::logMessage("RecognitionView::setViewName(const QString& name)");

    _viewName = name;
}

void RecognitionView::saveSnapshot(QImage& image)
{
    Logger::logMessage("RecognitionView::saveSnapshot(QImage& image)");

    SaveImageDialog dialog(this, image);
    dialog.exec();
}
